import os
import configparser
import yaml


class Readdata:
    # 读取yaml文件
    def read_yaml(self, path):
        with open(path, mode='r', encoding="utf-8") as file:
            result = yaml.load(stream=file, Loader=yaml.FullLoader)
            return result

    # 写进yaml文件
    def write_yaml(self, path, data):
        with open(path, mode='a', encoding='utf-8') as file:
            yaml.dump(stream=file, data=data)

    # 清空yaml文件
    def clear_yaml(self, path):
        with open(path, mode='w', encoding='utf-8') as file:
            file.truncate()

    # 读取ini文件
    def read_ini(self, path):
        cfg = configparser.ConfigParser()
        cfg.read(path, encoding="utf-8")
        return cfg
    
